package com.hcrazy.manchester.app.jdbc;

import java.util.List;

import com.hcrazy.manchester.app.pojo.BookMenu;

public class BookMenuDAO extends BaseDAO<BookMenu>{

	public void addBookMenu(BookMenu menu) throws Exception{
		StringBuffer sb = new StringBuffer();
		sb.append("insert into him_book_menu(");
		sb.append("menuName,menuNum,menuPic,menuParent,taste,menuDesc,type,menuCode,sellerId");
		sb.append(") values (");
		sb.append(":menuName,:menuNum,:menuPic,:menuParent,:taste,:menuDesc,:type,:menuCode,:sellerId");
		sb.append(")");
		
		update(sb.toString(), menu);
	}
	
	public void updateBookMenu(BookMenu menu) throws Exception{
		StringBuffer sb = new StringBuffer();
		sb.append("update him_book_menu set ");
		sb.append(" menuName=:menuName,menuNum=:menuNum,menuPic=:menuPic,menuParent=:menuParent,taste=:taste,menuDesc=:menuDesc,sellerId = :sellerId");
		sb.append(" where menuId = :menuId");
		
		update(sb.toString(), menu);
	}
	
	public List<BookMenu> listAllMenus(int type,long sellerId) throws Exception{
		String sql = "select * from him_book_menu where type = ? and sellerId = ? order by menuNum";
		return getList(sql, BookMenu.class,type,sellerId);
	}
	
	public BookMenu getById(int menuId) throws Exception{
		String sql = "select * from him_book_menu where menuId = ?";
		return this.getJavaBean(sql, BookMenu.class, menuId);
	}
	
	public List<BookMenu> getByParentId(int parentId) throws Exception{
		String sql = "select * from him_book_menu where menuParent = ?";
		return getList(sql, BookMenu.class,parentId);
	}
	
	public void delBookMenu(int menuId) throws Exception{
		String sql = "delete from him_book_menu where menuId = ?";
		this.commonUpdate(sql, menuId);
	}
	
	public void delBookMenuByParentId(int parentId) throws Exception{
		String sql = "delete from him_book_menu where menuParent = ?";
		this.commonUpdate(sql, parentId);
	}
	
}
